package com.ruoyi.carShopService.controller;

import com.ruoyi.carShopService.domain.ShopUserDto;
import com.ruoyi.carShopService.service.FindShopUserService;
import com.ruoyi.carShopService.util.JwtUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/find")
@CrossOrigin
public class FindShopUserController {

    @Autowired
    private FindShopUserService findShopUserService;

    @RequestMapping("/findShopUser")
    public AjaxResult findShopUser(@RequestHeader String token) throws Exception {

        Claims claims = JwtUtil.parseJWT(token);
        String subject = claims.getSubject();
        Long id = Long.parseLong(subject);
        ShopUserDto shopUser = findShopUserService.findShopUser(id);
        return AjaxResult.success(shopUser);
    }
}
